package com.example.huangliting.experimentalarrangementsystem.util;

import java.net.URLEncoder;
import java.util.Map;

public class HttpUtils {

    //public static String headerUrl = "http://192.168.43.4:8080/"; //热点

    //public static String headerUrl = "http://10.0.2.2:8080/";   //模拟器
    //public static String headerUrl = "http://10.34.12.135:8080/"; //student
    //public static String headerUrl = "http://192.168.191.9:8080/"; //刘煜的WIFI
    public static String headerUrl = "http://192.168.191.7:8080/"; //玲菲的WIFI
    /*
     * Function  :   封装请求体信息
     * Param     :   params请求体内容，encode编码格式
     */
    public static StringBuffer getRequestData(Map<String, String> params, String encode) {
        StringBuffer stringBuffer = new StringBuffer();        //存储封装好的请求体信息
        try {
            for(Map.Entry<String, String> entry : params.entrySet()) {
                stringBuffer.append(entry.getKey())
                        .append("=")
                        .append(URLEncoder.encode(entry.getValue(), encode))
                        .append("&");
            }
            stringBuffer.deleteCharAt(stringBuffer.length() - 1);    //删除最后的一个"&"
        } catch (Exception e) {
            e.printStackTrace();
        }
        return stringBuffer;
    }
}
